//package com.plian.system.controller.pm.assetleasingaudit;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.core.metadata.IPage;
//import com.plian.Tools.*;
//import com.plian.Tools.base.BaseController;
//import com.plian.Tools.pagedata.PageData;
//import com.plian.system.constant.sys.FormStatusConstant;
//import com.plian.system.constant.sys.FormTypeConstant;
//import com.plian.system.entity.pm.assetleasingaudit.AssetleasingAudit;
//import com.plian.system.model.CommonCode;
//import com.plian.system.model.ListResult;
//import com.plian.system.model.R;
//import com.plian.system.model.token.PassToken;
//import com.plian.system.mybatis.search.SearchEntity;
//import com.plian.system.mybatis.search.SearchParamEntiy;
//import com.plian.system.mybatis.support.Condition;
//import com.plian.system.mybatis.support.Query;
//import com.plian.system.service.pm.assetleasingaudit.IAssetleasingAuditService;
//import com.plian.system.service.sys.file.FileService;
//import com.plian.system.service.wf.FormWorkflowService;
//import com.plian.system.vo.pm.assetleasingaudit.AssetleasingAuditVO;
//import com.plian.system.wrapper.pm.assetleasingaudit.AssetleasingAuditWrapper;
//import lombok.AllArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.BeanUtils;
//import org.springframework.core.io.FileSystemResource;
//import org.springframework.http.ResponseEntity;
//import org.springframework.web.bind.annotation.*;
//
//import javax.validation.Valid;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Optional;
//
//@Slf4j
//@RestController
//@AllArgsConstructor
//@RequestMapping("api/assetleasingaudit")
//public class AssetleasingAuditController extends BaseController {
//
//    private IAssetleasingAuditService assetleasingAuditService;
//    private FileService fileService;
//    private FormWorkflowService formWorkflowService;
//
//    private AssetleasingAuditWrapper assetleasingAuditWrapper;
//
//    /**
//     * 详情
//     */
//    @PostMapping("/detail")
//    public R<AssetleasingAuditVO> detail(@Valid @RequestBody AssetleasingAudit assetleasingAudit) {
//        AssetleasingAudit detail = assetleasingAuditService.getOne(Condition.getQueryWrapper(assetleasingAudit));
//        AssetleasingAuditVO assetleasingAuditVO = assetleasingAuditWrapper.entityToVO(detail);
//        return R.data(assetleasingAuditVO);
//    }
//
//
//    /**
//     * 分页
//     */
//    @PostMapping("/list")
//    public ListResult<AssetleasingAuditVO> list(@Valid @RequestBody Query query) {
//        if (query.getAscs() == null && query.getDescs() == null) {
//            query.setAscs("code");
//            query.setDescs("create_time");
//        }
//
//        List<SearchEntity> entityList = query.getSearch();
//        QueryWrapper<AssetleasingAudit> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new AssetleasingAudit()), entityList
//        );
//        queryWrapper.eq("create_company_id", TokenUtil.getTokenOrgId());
//        IPage<AssetleasingAudit> pages = assetleasingAuditService.page(Condition.getPage(query), queryWrapper);
//
//        List<AssetleasingAuditVO> assetleasingAuditVOS = assetleasingAuditWrapper.entityToVO(pages.getRecords());
//        ListResult<AssetleasingAuditVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(assetleasingAuditVOS);
//        listResult.setTotal(Long.valueOf(pages.getTotal()).intValue());
//        return listResult;
//    }
//
//    /**
//     * 新增或修改
//     */
//    @PostMapping("/submit")
//    public R submit(@Valid @RequestBody AssetleasingAuditVO assetleasingAuditVO) {
//        Boolean checkResult = false;
//
//        if (!(Optional.ofNullable(assetleasingAuditVO.getStatus()).isPresent() && assetleasingAuditVO.getStatus() == FormStatusConstant.STASH)) {
//            checkResult = assetleasingAuditService.checkIsExisted(assetleasingAuditVO.getId(), assetleasingAuditVO.getCode());
//        }
//
//        if (checkResult) {
//            if (StringUtil.isBlank(assetleasingAuditVO.getVersion())) {
//                assetleasingAuditVO.setVersion("1");
//            }
//
//            if (Optional.ofNullable(assetleasingAuditVO.getStatus()).isPresent() && assetleasingAuditVO.getStatus() != FormStatusConstant.STASH) {
//                assetleasingAuditVO.setFormType(String.valueOf(FormTypeConstant.CQZC_SSETLEASING_AUDIT));
//            }
//            AssetleasingAudit assetleasingAudit = new AssetleasingAudit();
//            BeanUtils.copyProperties(assetleasingAuditVO, assetleasingAudit);
//            boolean result = assetleasingAuditService.saveOrUpdate(assetleasingAudit);
//            if (result) {
//                assetleasingAuditVO.setId(assetleasingAudit.getId());
//                List<HashMap> listDoc = assetleasingAuditVO.getList_doc();
//                fileService.edit(assetleasingAudit.getId().toString(), listDoc);
//            }
//
//            HashMap<String, Object> processVariable = new HashMap<>();
//            formWorkflowService.startProcessAndSimulate(String.valueOf(assetleasingAuditVO.getId()),assetleasingAuditVO.getFormType(),processVariable);
//
//            return result ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//        }else{
//            return new R(CommonCode.FAIL);
//        }
//    }
//
//    /**
//     * 删除
//     */
//    @PostMapping("/remove")
//    public R remove(@RequestBody PageData pd) {
//        List<String> ids = (List<String>) pd.get("ids");
//        return assetleasingAuditService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA))) ? new R(CommonCode.SUCCESS) : new R(CommonCode.FAIL);
//    }
//
//    /**
//     * 分页
//     */
//    @PostMapping("/reportList")
//    public ListResult<PageData> reportList( @RequestBody PageData pd) {
//        return assetleasingAuditService.reportList(pd);
//    }
//    /**
//     * 打印
//     */
//    @GetMapping("/buildpdf/{id}")
//    @PassToken
//    public ResponseEntity<FileSystemResource> buildPdf(@PathVariable Long id) {
//        return FileTools.exportPdf(assetleasingAuditService.buildpdf(id));
//    }
//
//}
